#include <iostream>
#include <vector>
using namespace std;
int slove(vector<int>& a) {
    if(a.size() == 0) {
        return -1;
    }
    if(a.size() == 1 || a[0] < a[1]) {
        return 0;
    }
    if(a[a.size() - 1] < a[a.size() - 2]) {
        return a.size() - 1;
    }
    int L = 1;
    int R = a.size() - 2;
    while(L < R) {
        int mid = (L + R) >> 1;
        if(a[mid] > a[mid - 1]) {
            R = mid - 1;
        }else if(a[mid] > a[mid + 1]) {
            L = mid + 1;
        }else {
            return mid;
        }
    }
    return L;
}
int main() {
    vector<int> a = { 6, 5, 3, 4, 6, 7, 8 };
    int k = slove(a);
    cout << "index = " << k << " the value is " << a[k] << endl;
    return 0;
}